package com.gzp.queue;

import javax.jms.JMSException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;

/**
 * 队列的消费者
 * 
 * @author Administrator
 *
 */
public class TestQueueConsumer {

	@SuppressWarnings("resource")
	public static void main(String[] args) throws JMSException {
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application-queue.xml");
		JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
//		jmsTemplate.setDefaultDestination(new ActiveMQQueue(""));// 该方法可以设置监听其它目的地
//		TextMessage textMessage = (TextMessage) jmsTemplate.receive();
//		System.out.println("消息接收成功，消息内容为：" + textMessage.getText());
		// 因为设置了SimpleMessageConverter消息转换器，可以用对象接收消息
		Object object = jmsTemplate.receiveAndConvert();
		System.out.println("消息接收成功，消息内容为：" + object);
	}
}
